<%--                                                                       --%>
<%-- Copyright (c) 2003-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
  String ctxPath = request.getContextPath();
%>

<jsp:useBean id="packageModelView" type="com.broadvision.web.util.ViewDynaBean" scope ="request"/>

<script language="JavaScript" src="<%= ctxPath %>/bp/js/user_popup_funcs.js"></script>

<script language="JavaScript">

  function check(field, button) {
    var SelectAllTxt = '<bean-el:message key="button.selectAll" bundle="bp.messages"/>';
    var UnselectAllTxt = '<bean-el:message key="button.unselectAll" bundle="bp.messages"/>';
    if (field == null) {
      button.value = SelectAllTxt;
    }
    var checkflag = "false";
    if (button.value == SelectAllTxt) {
      checkflag = "false";
    }
    if (button.value == UnselectAllTxt) {
      checkflag = "true";
    }
    var max = field.length;
    if (max > 1) {
      if (checkflag == "false") {
        for (i = 0; i < max; i++) {
          field[i].checked = true;
        }
        button.value = UnselectAllTxt;
      } else {
        for (i = 0; i < max; i++) {
          field[i].checked = false;
        }
        button.value = SelectAllTxt;
      }
    } else {
      if (checkflag == "false") {
        field.checked = true;
        button.value = UnselectAllTxt;
      } else {
        field.checked = false;
        button.value = SelectAllTxt;
      }
    }
  }
  
  function updateCheckbox(field, button) {
    var SelectAllTxt = '<bean-el:message key="button.selectAll" bundle="bp.messages"/>';
    var UnselectAllTxt = '<bean-el:message key="button.unselectAll" bundle="bp.messages"/>';
    if (field == null) {
      button.value = SelectAllTxt;
    }
    var checkflag = "false";
    if (button.value == SelectAllTxt) {
      checkflag = "false";
    }
    if (button.value == UnselectAllTxt) {
      checkflag = "true";
    }
    var max = field.length;
    if (max > 1) {
      if (checkflag == "false") {
        for (i = 0; i < max; i++) {
          if (field[i].checked == false) {
            return;
          }
        }
        button.value = UnselectAllTxt;
      } else {
        for (i = 0; i < max; i++) {
          if (field[i].checked == true) {
            return;
          }
        }
        button.value = SelectAllTxt;
      }
    } else {
      if (checkflag == "false") {
        if (field.checked == true) {
          button.value = UnselectAllTxt;
        }
      } else {
        if (field.checked == false) {
          button.value = SelectAllTxt;
        }
      }
    }
  }

  function isAnyChecked(field, alertmsg, confirmmsg) {
    if (field == null) {
      if (alertmsg != null && alertmsg.length > 0) {
        alert(alertmsg);
      }
      return false;
    }
    else if (field.length == null) {
      if (field.checked == false) {
        if (alertmsg != null && alertmsg.length > 0) {
          alert(alertmsg);
        }
        return false;
      }
      else {
        if (confirmmsg != null && confirmmsg.length > 0) {
          return confirm(confirmmsg);
        }
        else {
          return true;
        }
      }
    }
    else {
      for (var j = 0; j < field.length; j++) {
        if (field[j].checked) {
          if (confirmmsg != null && confirmmsg.length > 0) {
            return confirm(confirmmsg);
          }
          else {
            return true;
          }
        }
      }
      if (alertmsg != null && alertmsg.length > 0) {
        alert(alertmsg);
      }
      return false;
    }
  }


  function doPackageModelOnOffAction(myform, online) {
    var onOfflineMessage = '<bean-el:message key="bp.package.model.confirm.online" bundle="bp.messages"/>';
    if (online == 0) { 
      onOfflineMessage = '<bean-el:message key="bp.package.model.confirm.offline" bundle="bp.messages"/>';
    }
    if ( confirm(onOfflineMessage)){
      myform.oneOnly.value = false;
      myform.setStatus.value = online;
      myform.forwardAction.value = '/bp/packageModelList.do';
      myform.action = '<html-el:rewrite page="/bp/packageModelSetOnOffline.do"/>';
      myform.submit();
    }
    return false;
  }

  function doPackageOneModelOnOffAction(myform, online, processOid) {

    var onOfflineMessage = '<bean-el:message key="bp.package.model.confirm.online" bundle="bp.messages"/>';
    if (online == 0) { 
      onOfflineMessage = '<bean-el:message key="bp.package.model.confirm.offline" bundle="bp.messages"/>';
    }
    if ( confirm(onOfflineMessage)){
      myform.oneOnly.value = true;
      myform.setStatus.value = online;
      myform.oneModelId.value= processOid;
      myform.forwardAction.value = '/bp/packageModelList.do';
      myform.action = '<html-el:rewrite page="/bp/packageModelSetOnOffline.do"/>';
      myform.submit();
    }
    return false;
  }

  function doPackageModelAssignPMAction(myform) {
    myform.oneOnly.value = false;
    myform.forwardAction.value = '/bp/packageModelList.do';
    packageModelForm.modelManager.value = '';
    findUserPopup('<html-el:rewrite page="/mt/userSearchPopup.do"/>',
                    'packageModelForm','modelManager');
    return false;
  }
  
  function doPackageOneModelAssignPM(myform, processOid) {
    myform.oneModelId.value=processOid;
    myform.oneOnly.value = true;
    myform.forwardAction.value = '/bp/packageModelList.do';
    packageModelForm.modelManager.value = '';
    findUserPopup('<html-el:rewrite page="/mt/userSearchPopup.do"/>',
                    'packageModelForm','modelManager');
    return false;
  }

function setUserAlias(formName, fieldName, fieldValue) {
  // this page does not have any hidden fields that rely on the popup,
  // we do not need a refresh url.
  var refreshUrl = null;
  setFieldValueSimple(formName, fieldName, fieldValue);

  var theForm = eval("document." + formName);
  theForm.action = '<html-el:rewrite page="/bp/packageModelAssignPM.do"/>';
  theForm.submit();
  return false;
}
  
  
</script>

<% 
  java.util.HashMap map = new java.util.HashMap();
  String packageId = request.getParameter("id"); 
  map.put("id", packageId);
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>
	
<!-- Zone 5 starts here.  -->

<c:set var="editImg">
<img src="<%= ctxPath %>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>">
</c:set>
<c:set var="offlineImg">
<img src="<%= ctxPath %>/mc/images/action/icon_offline.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOffline" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.setOffline" bundle="mc.messages"/>">
</c:set>
<c:set var="onlineImg">
<img src="<%= ctxPath %>/mc/images/action/icon_online.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOnline" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.setOnline" bundle="mc.messages"/>">
</c:set>
<c:set var="assignImg">
<img src="<%= ctxPath %>/bp/images/action/icon_assign.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.assignPM" bundle="bp.messages"/>" title="<bean-el:message key="image.alt.assignPM" bundle="bp.messages"/>">
</c:set>

<html-el:form action="/bp/packageModelList.do">

<html-el:hidden property="id" />
<html-el:hidden property="setStatus" />
<html-el:hidden property="modelManager" />
<html-el:hidden property="oneOnly" />
<html-el:hidden property="oneModelId" />
<html-el:hidden property="forwardAction" />

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message key="bp.package.contentArea" bundle="bp.messages"/>">
  <tr>
    <td valign="top" width="100%">
		    
      <div class="pageTitle">
        <c:out value="${packageModelView.map.name}" />
      </div> 
			
      <!-- pageTab -->
      <div class="errorMessage"><html-el:errors bundle="bp.messages"/></div>
      <%@include file="/mc/common/pagetab.jsp" %>
      <!-- end of PageTab -->
      <%
        String packageName = (String) packageModelView.get("name");
      %>
      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="bp.package.models" arg0="<%=packageName%>" bundle="bp.messages"/></span>
        <span class="right">&nbsp;</span>
      </div> 
			
<!-- Start List here -->

      <bean:size id="modelCount" name="packageModelView" property="models" />

      <logic:equal name="packageModelView" property="canEdit" value="true">
	<logic:equal name="modelCount" value="0">
          <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Alert List" width="100%">
            <tr class="listHeader"> 
              <th id="ModelName" align="left"><bean-el:message key="bp.package.modelName" bundle="bp.messages"/></th>
              <th id="Description" align="left"><bean-el:message key="bp.package.modelDescription" bundle="bp.messages"/></th>
              <th id="ProcessModelManager" align="left"><bean-el:message key="bp.package.modelManager" bundle="bp.messages"/></th>
              <th id="Status" align="left"><bean-el:message key="bp.package.modelStatus" bundle="bp.messages"/></th>
              <th id="Action" align="left" nowrap><bean-el:message key="header.actions"  bundle="bp.messages"/></th>
            </tr>

            <tr class="listEven">
              <td align="center" colspan="5">
                <bean-el:message key="bp.package.model.noModel" bundle="bp.messages"/>
              </td>
            </tr>
          </table>
        </logic:equal>

	<logic:notEqual name="modelCount" value="0">
          <div class="globalButtonWrap">
            <input type="button" name="selectAllModels" class="globalButton" onclick="check(this.form.modelIds, this);" value='<bean-el:message key="button.selectAll" bundle="bp.messages"/>'>
            <logic:equal name="packageModelView" property="packOnline" value="1">
              <logic:equal name="packageModelView" property="deployStatus" value="1">
                <input type="button" name="setOnline" class="globalButton" onclick="if (isAnyChecked(this.form.modelIds, '<bean-el:message key="bp.package.alert.atLeastOneModel" bundle="bp.messages"/>', '')) doPackageModelOnOffAction(this.form, 1);" value='<bean-el:message key="button.setOnline" bundle="bp.messages"/>'>
                <input type="button" name="setOffline" class="globalButton" onclick="if (isAnyChecked(this.form.modelIds, '<bean-el:message key="bp.package.alert.atLeastOneModel" bundle="bp.messages"/>', '')) doPackageModelOnOffAction(this.form, 0);" value='<bean-el:message key="button.setOffline" bundle="bp.messages"/>'>
              </logic:equal>
            </logic:equal>
            <input type="button" name="assignPM" class="globalButton" onclick="if (isAnyChecked(this.form.modelIds, '<bean-el:message key="bp.package.alert.atLeastOneModel" bundle="bp.messages"/>', '')) doPackageModelAssignPMAction(this.form);" value='<bean-el:message key="button.assignPM" bundle="bp.messages"/>'>
          </div>

          <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Alert List" width="100%">
            <tr class="listHeader"> 
              <th id="Checkboxes">&nbsp;</th>
              <th id="ModelName" align="left"><bean-el:message key="bp.package.modelName" bundle="bp.messages"/></th>
              <th id="Description" align="left"><bean-el:message key="bp.package.modelDescription" bundle="bp.messages"/></th>
              <th id="ProcessModelManager" align="left"><bean-el:message key="bp.package.modelManager" bundle="bp.messages"/></th>
              <th id="Status" align="left"><bean-el:message key="bp.package.modelStatus" bundle="bp.messages"/></th>
              <th id="Action" align="left" nowrap><bean-el:message key="header.actions"  bundle="bp.messages"/></th>
            </tr>

            <logic:iterate id="model" name="packageModelView" property="models" indexId="i">
              <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd"
%>">
                <td headers="Checkboxes" align="center">
                  <input type="checkbox" name="modelIds" onclick="updateCheckbox(this.form.modelIds, this.form.selectAllModels);" value="<c:out value="${model.map.id}"/>">
                </td>
                <td headers="ModelName">
                  <html-el:link page="/bp/processView.do" paramId="processOid" paramName="model" paramProperty="id" >
                    <c:out value="${model.map.name}"/>
                  </html-el:link>
                </td>
                <td headers="Description">
                  <c:out value="${model.map.description}"/>
                </td>
                <td headers="ProcessModelManager">
                  <c:out value="${model.map.managerFullName}"/>
                </td>
                <td headers="Status">
                  <logic:equal name="model" property="status" value="0">
                    <bean-el:message key="bp.process.status.inDeployment" bundle="bp.messages"/>
                  </logic:equal>
                  <logic:equal name="model" property="status" value="1">
                    <logic:equal name="model" property="online" value="true">
                      <bean-el:message key="bp.process.status.online" bundle="bp.messages"/>
                    </logic:equal>
                    <logic:equal name="model" property="online" value="false">
                      <bean-el:message key="bp.process.status.offline" bundle="bp.messages"/>
                    </logic:equal>
                  </logic:equal>
                  <logic:equal name="model" property="status" value="2">
                    <bean-el:message key="bp.process.status.error" bundle="bp.messages"/>
                  </logic:equal>
                  <logic:equal name="model" property="status" value="3">
                    <bean-el:message key="bp.process.status.toBeConfigured" bundle="bp.messages"/>
                  </logic:equal>
                </td>
                <td nowrap align="left" headers="Action">
                  <html-el:link page="/bp/processEdit.do" paramId="processOid" paramName="model" paramProperty="id" >
                    <c:out value='${editImg}' escapeXml="false"/>
                  </html-el:link>

                  <logic:equal name="model" property="status" value="1">
                    <logic:equal name="packageModelView" property="packOnline" value="1">
                      <logic:equal name="packageModelView" property="deployStatus" value="1">
                        <logic:equal name="model" property="online" value="false">
                          <a href="#" onclick="javascript:return doPackageOneModelOnOffAction(document.packageModelForm, 1, '<c:out value="${model.map.id}"/>');"><c:out value='${onlineImg}' escapeXml="false"/></a>
                        </logic:equal>
                        <logic:equal name="model" property="online" value="true">
                          <a href="#" onclick="javascript:return doPackageOneModelOnOffAction(document.packageModelForm, 0, '<c:out value="${model.map.id}"/>');"><c:out value='${offlineImg}' escapeXml="false"/></a>
                        </logic:equal>
                      </logic:equal>
                    </logic:equal>
                  </logic:equal>
                  <a href="#" onclick="javascript:doPackageOneModelAssignPM(document.packageModelForm, '<c:out value="${model.map.id}"/>');"><c:out value='${assignImg}' escapeXml="false"/></a>
                </td>
              </tr>
            </logic:iterate>
          </table>
        </logic:notEqual>
      </logic:equal>

      <logic:notEqual name="packageModelView" property="canEdit" value="true">
        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Alert List" width="100%">
          <tr class="listHeader"> 
            <th id="ModelName" align="left"><bean-el:message key="bp.package.modelName" bundle="bp.messages"/></th>
            <th id="Description" align="left"><bean-el:message key="bp.package.modelDescription" bundle="bp.messages"/></th>
            <th id="ProcessModelManager" align="left"><bean-el:message key="bp.package.modelManager" bundle="bp.messages"/></th>
            <th id="Status" align="left"><bean-el:message key="bp.package.modelStatus" bundle="bp.messages"/></th>
          </tr>

          <logic:equal name="modelCount" value="0">
            <tr class="listEven">
              <td align="center" colspan="4">
                <bean-el:message key="bp.package.model.noModel" bundle="bp.messages"/>
              </td>
            </tr>
          </logic:equal>

          <logic:notEqual name="modelCount" value="0">

            <logic:iterate id="model" name="packageModelView" property="models" indexId="i">
              <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd"
%>">
                <td headers="ModelName">
                  <html-el:link page="/bp/processView.do" paramId="processOid" paramName="model" paramProperty="id" >
                    <c:out value="${model.map.name}"/>
                  </html-el:link>
                </td>
                <td headers="Description">
                  <c:out value="${model.map.description}"/>
                </td>
                <td headers="ProcessModelManager">
                  <c:out value="${model.map.managerFullName}"/>
                </td>
                <td headers="Status">
                  <logic:equal name="model" property="status" value="0">
                    <bean-el:message key="bp.process.status.inDeployment" bundle="bp.messages"/>
                  </logic:equal>
                  <logic:equal name="model" property="status" value="1">
                    <logic:equal name="model" property="online" value="true">
                      <bean-el:message key="bp.process.status.online" bundle="bp.messages"/>
                    </logic:equal>
                    <logic:equal name="model" property="online" value="false">
                      <bean-el:message key="bp.process.status.offline" bundle="bp.messages"/>
                    </logic:equal>
                  </logic:equal>
                  <logic:equal name="model" property="status" value="2">
                    <bean-el:message key="bp.process.status.error" bundle="bp.messages"/>
                  </logic:equal>
                  <logic:equal name="model" property="status" value="3">
                    <bean-el:message key="bp.process.status.toBeConfigured" bundle="bp.messages"/>
                  </logic:equal>
                </td>
              </tr>
            </logic:iterate>
          </logic:notEqual>
        </table>
      </logic:notEqual>
<!--end list here-->
	  
    </td>
  </tr>
</table>

</html-el:form>
<!--end zone 5 content here -->
